# Based on http://cr.openjdk.java.net/~dlsmith/jsr335-0.6.2/C.html

(if (>= (javaVersion T) (1 7) )
  (de javaDefInstance (Methods Fields SimpleClass)
    (let (@SimpleClass (intern SimpleClass)
          Methods (methodsAsMethodHandles Methods "Static" T) )
      (javaDefInstanceFields Fields SimpleClass)
      (for Method Methods
        (let (MethodName (instanceMember (car Method) ">")
              Method (cdr Method)
              @Methods (methodHandlesSymbol MethodName Method) )
          (when @Methods
            (def MethodName
              (fill
                (quote (@SimpleClass . @)
                  (use @Methods
                    (if (=T @SimpleClass)
                      (let "@Curry" (next)
                        (curry ("@Curry") @
                          (pass invokeMethodHandles
                            @Methods "@Curry") ) )
                      (pass invokeMethodHandles
                        @Methods @SimpleClass) ) ) ) ) ) ) ) ) ) )
  (de javaDefInstance (Methods Fields SimpleClass)
    (let (@SimpleClass (intern SimpleClass)
          Methods (memberNames Methods "Static" T) )
      (javaDefInstanceFields Fields SimpleClass)
      (for @Method Methods
        (let MethodName (instanceMember @Method ">")
          (or (fun? (val MethodName) )
            (def MethodName
              (fill
                (quote (@SimpleClass . @)
                  (if (=T @SimpleClass)
                    (let "@Curry" (next)
                      (curry ("@Curry") @
                        (pass 'java+ "@Curry" @Method) ) )
                    (pass 'java+ @SimpleClass @Method) ) ) ) ) ) ) ) ) ) )